import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import qs from 'qs'
import persistedState from 'vuex-persistedstate'
Vue.use(Vuex)

const store = new Vuex.Store({
  plugins: [persistedState(
    { storage: window.sessionStorage }
  )],
  state: {
    bbl_sqdwid: '',
    bbl_sub_mchid: '',
    bbl_phone: '',
    rightflag: true,
    fenleiId: null,
    ids: null,
    treeid: null,
    inputCn: '',
    inputEn: '',
    inputRu: '',
    inputJa: '',
    inputDw: '',
    show: [],
    showCn: "",
    showEn: "",
    showRu: "",
    showJa: "",
    showDw: "",
    datatitle: "",
    cpjslist: [],
    cpimglist: [],

    cppicname: [{
      Cn: '',
      En: '',
      Dy: '',
      Rw: '',
      Ew: '',
    }],
    token:'',
    columns: [],
    myCars: [],
    columschil: [],
    exflage: false,
    cpimgids: '',
    flnamedata: [],
    dataSourceCn: [],
    dataSourceEn: [],

    wzfl: false, //文章管理---高级-管理分类
    tjwz: false, //添加文章
    // xzlflg:false,//管理文章--选择列
    editable: false, //文章分类---修改
    filename: sessionStorage.getItem('sqdwid'),
    dwmc: sessionStorage.getItem('dwmc'),
    articleName: [], //文章分类

    //管理文章---修改--开始
    xiugaiflag: "",
    id_num: '',
    title: '', //文章标题
    content: "", //富文本编辑器
    articleClass: "", //获取文章分类
    pushTime: "", //获取发布时间
    source: "", //获取来源
    author: "", //获取作者
    articleRemark: "", //获取文章摘要
    picList: "", //获取列表图片
    browserTitle: "", //获取优化的浏览器标题
    browserKeyword: "", //获取优化的浏览器详情页关键字
    browserDescribe: "", //获取优化的浏览器详情页描述
    glxgsqdwid: '', //管理文章修改---sqdwid
    radiolang: "",
    //管理文章---修改---结束
    sqdwid: sessionStorage.getItem('sqdwid'),
    gysmc: sessionStorage.getItem('dwmc'),
    //样本索引
    ybsydata: [],
    ybindex: [],
    xhColNum: [],
    wjradio: null,
    kdradio: null,
    njradio: null,
    qycpymID: "",
    zlradio: null,
    bjlstk: false, //报价
    jsgl: false, //权限--角色管理
    tgtk: false, //产品管理
    tjhy: false, //添加会员
    defaultActiveKey: "1", //添加会员---tab key值
    kpxx: false,
    kpxxflg: false,
    kpxxbj: false,
    shdz: false,
    shdzbj: false,
    cpscym: false,
    bjdata: {}, //报价列表中的报价数据添加
    xjxh: '', //询价型号
    qywzkhid: '', //客户名称ID
    qywzgsmc: '', //客户名称ID
    fldata: [], //分类
    fldataidnum: [],
    bjdata: {}, //报价列表中的报价数据添加
    xjxh: '', //询价型号
    xgtj: false, //修改特价判断值
    tjdata: {}, //特价列表中的特价数据修改
    xggy: false, //修改供应判断值
    gydata: {}, //供应列表中的供应数据修改
    fileList: [],
    hygllist: [],
    editInvoice: [], //修改开票信息
    editAddress: [], //修改收货地址
    cpglxg: [], //修改收货地址
    tabskey: '',
    tabslist: [],
    tableParam: '', //样本--产品参数--exel表格数据
    zlColNumExist: null,
    power: JSON.parse(sessionStorage.getItem('power')),//APP---权限控制
    powerID: [],
    // 进件客户--修改赋值
    // jjkhlistdata:"1111111"
    tjxceditflag: false,
    fbxwflag: false,
    modifyval: '',
    fbzsval: '',
    tabsname: [{
      newsType: 1,
      tabdata: 'chen'
    }],
    tabsfbzsname: [
      { tp: "gcsdy", name: "工程师答疑", channelId: "1012", classId: "0" },
    ],
    fh_index: [{
      tabs_index: 0,
      page_index: 1,
      xwkeyword: '',
    }],
    // 运单信息
    xsdinfo:'',
    // 公司编码
    gsbm:sessionStorage.getItem("gsbm"),
    rwr:'',
    database: 'ERP2_BEARING',
    ip: '122.112.240.180',
    baseurl:'https://yb.bearing.cn',
    //修改联系人缓存联系人数据
    lxrList:'',
    // 联系人数据索引
    lxr_i:"",
    //修改收货人缓存联系人数据
    shrList:'',
    // 收货人数据索引
    shr_i:"",

    selectedrecord:[],
    path_num:0,
    qx_checkedbox:'',
    // 客户名录传type值
    khml_type:'',
    jgqx:'',
    smt_token:sessionStorage.getItem('smt_token')
  },
  mutations: {
    //目录设置--绑定数据
    getSampleDetail(state) {
      this.state.xhColNum = []
      axios.post("yangben/SampleDetail.php", qs.stringify({
        sqdwid: this.state.sqdwid == null ? this.state.bbl_sqdwid : this.state.sqdwid,
        filename: this.state.filename == null ? this.state.bbl_sqdwid : this.state.filename,
        fenleiId: this.state.fenleiId,
        ids: this.state.ids
      })).then(res => {
        if (res.data.code == 303) {
          this.state.ybindex = res.data.result.tableParam.tableFiled

          if (res.data.result.Column.colNumDate != []) {
            if (this.state.ids != '0') {
              let xhColNums = []
              xhColNums = res.data.result.Column.colNumDate.xhColNum.split('|')

              if (xhColNums.length > 0) {

                for (var i = 0; i < xhColNums.length; i++) {
                  if (Number(xhColNums[i])) {

                    this.state.xhColNum.push(Number(xhColNums[i]))

                  }
                }
              }
              else {
                this.state.xhColNum.push(1)
              }

              this.state.kdColNum = res.data.result.Column.colNumDate.kdColNum
              this.state.njColNum = res.data.result.Column.colNumDate.njColNum
              this.state.wjColNum = res.data.result.Column.colNumDate.wjColNum
              this.state.zlColNum = res.data.result.Column.colNumDate.zlColNum
              this.state.zlColNumExist = res.data.result.Column.zlColNumExist
            }
          }

          this.state.wjradio = Number(this.state.wjColNum)
          this.state.njradio = Number(this.state.njColNum)
          this.state.kdradio = Number(this.state.kdColNum)
          this.state.zlradio = Number(this.state.zlColNum)
          //样本索引---结束

          //目录设置-根据给的值判断是否可编辑
          if (res.data.result.language.length != 0) {
            for (var i = 0; i < res.data.result.language.length; i++) {

              if (res.data.result.language[i].language == 0) {
                state.showCn = res.data.result.language[i].show
              }
              if (res.data.result.language[i].language == 1) {
                state.showEn = res.data.result.language[i].show
              }
              if (res.data.result.language[i].language == 2) {
                state.showDw = res.data.result.language[i].show
              }
              if (res.data.result.language[i].language == 3) {
                state.showJa = res.data.result.language[i].show
              }
              if (res.data.result.language[i].language == 4) {
                state.showRu = res.data.result.language[i].show

              }
            }
          }
          //产品介绍----
          if (res.data.result.introduce.length != 0) {
            state.cpjslist = res.data.result.introduce
            for (var i = 0; i < res.data.result.introduce.length; i++) {
              state.cpjslist[i].key = i
            }
          } else {
            state.cpjslist = []
          }

          //产品图 ------开始.
          if (res.data.result.picLgType.length != 0) {
            state.cpimglist = res.data.result.picLgType
            for (var i = 0; i < res.data.result.picLgType.length; i++) {
              state.cpimglist[i].key = i
            }
          } else {
            state.cpimglist = []
          }

          //产品图 ------结束
          for (var i = 0; i < res.data.result.menuLgType.length; i++) {
            if (res.data.result.menuLgType[i].language == 0) {
              state.inputCn = res.data.result.menuLgType[0].DName
            } else if (res.data.result.menuLgType[i].language == 1) {
              state.inputEn = res.data.result.menuLgType[1].DName
            } else if (res.data.result.menuLgType[i].language == 2) {
              state.inputRu = res.data.result.menuLgType[2].DName

            } else if (res.data.result.menuLgType[i].language == 3) {
              state.inputJa = res.data.result.menuLgType[3].DName

            } else if (res.data.result.menuLgType[i].language == 4) {
              state.inputDw = res.data.result.menuLgType[4].DName

            }


          }

          //产品参数---exel tableData
          this.state.tableParam = res.data.result.tableParam
          if (res.data.result.tableParam.tableFiled[0].tableData != undefined) {
            state.myCars = res.data.result.tableParam.tableDate
            state.columns = res.data.result.tableParam.tableFiled[0].tableData
          }
        }
      })
    },
    //分类名称获取
    getdatalist() {

      axios.post("yangben/sampleEntrySmall.php").then(res => {
        if (res.data.code == 303) {
          this.state.flnamedata = [];
          for (var i = 0; i < res.data.result.data.length; i++) {
            this.state.flnamedata.push(res.data.result.data[i].CnName)
            this.state.dataSourceCn.push(res.data.result.data[i].CnName)
            this.state.dataSourceEn.push(res.data.result.data[i].EnName)
          }
        }
      })
    },
    //文章分类列表
    getwzfl() {
      axios.post("wenzhang/ArticleClassList.php", qs.stringify({
        sqdwid: this.state.glxgsqdwid == "" ? sessionStorage.getItem('sqdwid') : this.state.glxgsqdwid,
        language: '0'
      })).then(res => {
        console.log(res)
        if (res.data.code == 303) {
          this.state.articleName = res.data.result.data
          // console.log(this.state.articleName)
          // console.log(this.state.articleClass)
          for (var i = 0; i < this.state.articleName.length; i++) {
            this.state.fldata.push(this.state.articleName[i].articleName)
            if (this.state.articleName[i].id_num == this.state.articleClass) {
              this.state.articleClass = this.state.articleName[i].articleName
            } else {
              this.state.articleClass = '请选择分类'
            }
          }
        } else {
          this.state.articleName = []
        }

      })
    },
    //样本索引
    getybsy() {
      axios.post("yangben/SampleDetailYbIndex.php", qs.stringify({
        filename: this.state.filename,
        ids: this.state.ids,
      })).then(res => {
        console.log(res)
        if (res.data.code == 303) {
          this.state.ybsydata = res.data.result.data
          for (var i = 0; i < res.data.result.data.length; i++) {
            this.state.ybsydata[i].key = i
          }
        } else {
          this.state.ybsydata = []
        }
      })
    },
    getpower(state, power) {
      state.power = power

    },

    //样本索引
  },
  actions: {

  }
})
export default store